import java.util.Iterator;
import java.util.Vector;

/**
 * Class holding the structure of a Road.
 * @author Jared Lindbl�m, Prarthanaag
 */
public class Road {
	private String name, type;
	private int weight;
	private double distance;
	protected int maxVehicles;
	protected Vector<Intersection> intersections;

	/**
	 * Constructor.
	 * @param name			The name of the road.
	 * @param weight		The weight of the road.
	 * @param maxVehicles	The maximum number of vehicles on this road.
	 * @param type			The road type (North/South, East/West).
	 */
	public Road(String name, double distance, int weight, int maxVehicles, String type) {
		this.name = name;
		this.distance = distance;
		this.weight = weight;
		this.maxVehicles = maxVehicles;
		this.type = type; // North/South or East/West
		intersections = new Vector<Intersection>();
	}

	/**
	 * Accessor Method (Name).
	 * @return	The name of the road.
	 */
	public String getName() {
		return name;
	}

	/**
	 * Accessor Method (Type).
	 * @return	The road type (North/South, East/West).
	 */
	public String getType() {
		return type;
	}

	/**
	 * Accessor Method (Distance).
	 * @return The length of the road.
	 */
	public double getDistance() {
		return distance;
	}

	/**
	 * Accessor Method (Weight).
	 * @return	The weight of the road.
	 */
	public int getWeight() {
		return weight;
	}

	/**
	 * Dummy Method... Implemented in subclasses
	 * @param direction	The direction the vehicle is traveling.
	 * @return	The number of vehicles on the road.
	 */
	public int getNumVehicles (Direction direction) {
		/**
		 * Implemented in subclasses!
		 */
		return -1;
	}

	/**
	 * Accessor Method (Max Vehicles).
	 * @return	The maximum number of vehicles on this road.
	 */
	public int getMaxVehicles() {
		return maxVehicles;
	}

	/**
	 * Accessor Method (Intersection).
	 * @return The intersections associated with this road.
	 */
	public Intersection[] getIntersections() {
		Intersection[] i = new Intersection[intersections.size()];

		intersections.toArray(i);
		return i;
	}

	/**
	 * Updates the weight of this road.
	 * @param weight	The new weight for this road.
	 */
	public void updateWeight(int weight) {
		this.weight = weight;
	}

	/**
	 * Updates the maximum number of vehicles on this road.
	 * @param maxVehicles	The new maximum number of vehicles on this road.
	 */
	public void updateMaxVehicles(int maxVehicles) {
		this.maxVehicles = maxVehicles;
	}

	/**
	 * Associates an intersection to this road.
	 * @param intersection	The intersection to associate to this road.
	 */
	public void addIntersection(Intersection intersection) {
		intersections.addElement(intersection);
	}

	/**
	 * Dummy Method... Implemented in subclasses.
	 * @param vehicle 		The vehicle to be removed.
	 * @param direction 	The direction in which to remove the vehicle.
	 * @return True/false if vehicle could be removed.
	 */
	public boolean removeVehicle(Vehicle vehicle, Direction direction) {
		/**
		 * Implemented in subclasses!
		 */
		return false;
	}

	/**
	 * Prints out the structure of this road (for debugging).
	 * @see java.lang.Object#toString()
	 */
	public String toString() {
		String print = "Name: " + name + "\t\tWeight: " + weight + "\t\tMaxVehicles: " + maxVehicles + "\n";

		Iterator<Intersection> it = intersections.iterator();

		print = print.concat("\n\t\t\t\tAssociated Intersections: (" + intersections.size() + " in total)\n\n");
		while(it.hasNext()) {
			print = print.concat("\t\t\t\t\tName: " + (it.next()).getName() + "\n");
		}

		return print;
	}
}